home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / comm / irc / UnrealIRCd-bin.lha / Unreal / doc / crypto.doc < prev    next >
Encoding:
Text File  |  2000-08-21  |  5.9 KB  |  192 lines

  1.  
  2.                              UnrealIRCd Encryption Protocol
  3.                                     version 1.0
  4.                          by Carsten V. Munk (stskeeps@tspre.org)
  5.  
  6.  
  7. 1. Introduction
  8. ---------------
  9.  
  10. As of UnrealIRCd version 3.1 we have included capability for secure
  11. connections (Encrypted IRC connections). This was done after I read an "Ask
  12. Slashdot" article at slashdot.org, (http://slashdot.org/askslashdot/00/04/19/0443251.shtml)
  13. where a guy asked:
  14.  
  15. cylent asks: "I have a close-knit group of acquaintances that like to communicate with each other
  16. often. Public IRC servers are fine for chit-chat, although for more in-depth discussions a more
  17. secure form of communication is preferred. I'm wondering what GPL'd software exists to provide for a
  18. secure form of realtime multi-party communication. Are there any IRC servers/clients that support any
  19. form of public key cryptography? Blowfish? 3DES? Are there any other proprietary "chat"
  20. programs available with a forte in cryptography?".
  21.  
  22. I sat down, did some thoughts. The thing would not be public key, as I
  23. believe client and server should have a keyfile, picked up by SSL, SSH
  24. whatever. The communication would be client<->server, so that the stream
  25. would be encrypted. Safest way to ensure 100% secure communications would be
  26. to set up the IRC server, and join in with only secure communications to
  27. same channel where no non secure clients were and set it +is.
  28. Server<->server communications are not encrypted (yet), but we're working on
  29. it. However, here is a description of the protocol:
  30.  
  31. 2. System Requiriments
  32. --------------------------------
  33.  
  34. * OpenSSL (with libcrypto), win32 port also availible, read unreal.tspre.org
  35.   for more information. Read http://www.openssl.org for more information
  36.   (you need the openssl/ directory in includes to compile)
  37.  
  38.  
  39. 3. Negotiating the secure connection
  40. ------------------------------------
  41.  
  42. The client connects, and sends: (normal irc with \r\n as terminates)
  43.  
  44. CRYPTO <algoritm> <keyfilename> <parameters>
  45.         |               |          |
  46.         |               |          \--- Unused currently, use "*"
  47.         |               \--- The name of the file in keys/ containing the key
  48.         \--- This is algoritm name, in uppercase (see algoritm list)
  49.  
  50. NOTE: the keyfilename must not contain a / or a \
  51.  
  52. Until connection is negotiated the connection is in non-secure mode (normal
  53. irc protocol, see RFC 1459)
  54.  
  55. The server then responds, if the key was acknowledged:
  56.  
  57. CRYPTO ON <algoritm>
  58.               \---- (see algoritm list, this is in uppercase)
  59.  
  60. and the connecting is marked as secure, sending secure packets now.
  61.  
  62. The server responds, if an error has occoured:
  63.  
  64. CRYPTO ERROR :test
  65.  
  66. And the secure connection is disabled
  67.  
  68. Some example errors:
  69.  
  70. CRYPTO ERROR :Illegal keypath
  71. -  Means that keyfilename in CRYPTO command was illegal
  72.  
  73. CRYPTO ERROR :Failed to open keyfile <filename>
  74. -  Means that the IRCd failed to open the keyfile
  75.  
  76. CRYPTO ERROR :Unable to read keyfile <filename>
  77. -  Means that the IRCd failed to read the keyfile
  78.  
  79. CRYPTO ERROR :No such method/command <command>
  80. -  Means that the method (algoritm) or command does not exist
  81.  
  82. 4. The stream packets
  83. ---------------------
  84.  
  85. When secure mode (CRYPTO ON), is acknowledged the IRCd sends, and expects
  86. to recieve packets with the encrypted data.
  87.  
  88. The packet is started with a header
  89.  
  90. struct    crypto_header
  91. {    
  92.     unsigned char     highbyte;
  93.     unsigned char    lowbyte;    
  94. };
  95.  
  96. after the header, a buffer with exact length ((highbyte * 256) + lowbyte)
  97. is coming after (binary buffer). When the string is recieved, decrypt using
  98. the cipher.
  99.  
  100. Example function: (this decrypts a buffer), wont work with direct paste, but
  101. you can see the principle:
  102.  
  103. char    *ep_decrypt(aClient *cptr, char *string)
  104. {
  105.         static char     decryptbuffer[8192];
  106.         int     num;
  107.         char    ivec[9];
  108.         int     length;
  109.  
  110.         if (!cptr->cryptinfo)
  111.                 return string;
  112.  
  113.         bzero(decryptbuffer, sizeof(decryptbuffer));
  114.         bzero(ivec, sizeof(ivec));
  115.         num = 0;
  116.         length = (*(string) * 256) + (*(string + 1));
  117.  
  118.         if (cptr->cryptinfo->method == METHOD_BLOWFISH)
  119.         {
  120.                 BF_cfb64_encrypt(string + 2, decryptbuffer, length, 
  121.             cptr->cryptinfo->key, ivec, &num, BF_DECRYPT);
  122.                 return (decryptbuffer);
  123.         }
  124. }
  125.  
  126. The IRCd expects same format back, here is what the ircd encrypts with:
  127.  
  128. char    *ep_encrypt(aClient *cptr, char *string, int *len)
  129. {
  130.         static unsigned char    cryptobuffer[8192];
  131.         char            ivec[9];
  132.         int             length;
  133.         char            *c;
  134.         int             num;
  135.  
  136.         if (!cptr->cryptinfo)
  137.                 return string;
  138.  
  139.         bzero(cryptobuffer, sizeof(cryptobuffer));
  140.         bzero(ivec, sizeof(ivec));
  141.         num = 0;
  142.  
  143.         if ((c = (char *)strchr(string, '\n')))
  144.                 *c = '\0';
  145.         if ((c = (char *)strchr(string, '\r')))
  146.                 *c = '\0';
  147.  
  148.         length = strlen(string) + 1;
  149.         cryptobuffer[0] = (unsigned char) length / 256;
  150.         cryptobuffer[1] = (unsigned char) length - (cryptobuffer[0] * 256);
  151.  
  152.         if (cptr->cryptinfo->method == METHOD_BLOWFISH)
  153.         {
  154.                 BF_cfb64_encrypt(string, &cryptobuffer[2], length,
  155.             cptr->cryptinfo->key, ivec, &num, BF_ENCRYPT);
  156.  
  157.                 *len = length + 2;
  158.                 return (cryptobuffer);
  159.         }
  160. }
  161.  
  162.  
  163. To abort the secure connection, either QUIT (to exit completely), or
  164. send CRYPTO OFF.
  165.  
  166.  
  167. 5. Algoritms
  168. ------------
  169.  
  170. As of Unreal3.1 only BLOWFISH is implemented, but there will be patches
  171. for extended algoritms. We use the <openssl/blowfish.h> include at the
  172. moment. 
  173.  
  174. Mail stskeeps@tspre.org if you show interest in other algoritms
  175.  
  176. 6. Credits
  177. ----------
  178.  
  179. Credits to the UnrealIRCd team (me, codemastr, DrBin)
  180.  
  181. Credits to slashdot.org as well.
  182.  
  183. This product includes software developed by Eric Young (eay@cryptsoft.com)
  184.  
  185.  
  186. 7. Contact info
  187. ----------------
  188.  
  189. Mail stskeeps@tspre.org for any questions
  190.  
  191.  
  192.